package com.gitee.feizns.explore.data_structure.array_and_string;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author feizns
 * @since 2019/10/11
 */
public class YanHuiTriangle {

    public static void main(String[] args) {
        System.out.println(
                getRow(3)
                .stream()
                .map(Objects::toString)
                .collect(Collectors.joining(","))
                .toString()
        );
    }

    public static List<Integer> getRow(int rowIndex) {
        if ( rowIndex == 0 )
            return Arrays.asList(1);
        else if ( rowIndex == 1 )
            return Arrays.asList(1, 1);

        List<Integer> row = getRow(rowIndex - 1);
        List<Integer> ret = new LinkedList<>();

        for (int i = 0; i < row.size() - 1; i++) {
            ret.add(row.get(i) + row.get(i + 1));
        }

        ((LinkedList<Integer>) ret).addFirst(1);
        ((LinkedList<Integer>) ret).addLast(1);
        return ret;
    }

}
